from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
from mall import settings
from django.core.mail import send_mail
from celery_tasks.main import app

@app.task(name='send_verificate_email')
def send_verificate_email(email_to,user_id):
    subject = '美多商城邮箱验证'
    message = ''
    from_email = 'qi_rui_hua@163.com'
    recipient_list = [email_to]
    html_message = ''

    s = Serializer(secret_key=settings.SECRET_KEY, expires_in=3600)
    data = {
        'id': user_id,
        'email': email_to
    }
    token = s.dumps(data)

    verify_url = 'http://www.meiduo.site:8080/success_verify_email.html?token=%s' % token.decode()

    html_message = '<p>尊敬的用户您好！</p>' \
                   '<p>感谢您使用美多商城。</p>' \
                   '<p>您的邮箱为：%s 。请点击此链接激活您的邮箱：</p>' \
                   '<p><a href="%s">%s<a></p>' % (email_to, verify_url, verify_url)

    send_mail(subject=subject,
              message=message,
              from_email=from_email,
              recipient_list=recipient_list,
              html_message=html_message)